package code.example.base.jvm;

import code.example.tool.LogFactory;

import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.ManagementFactory;
import java.util.Iterator;
import java.util.List;

public class ManagementFactoryTester {
    public void getGCMessage(){
        byte [] data = null;
        for(int i=0;i<10000000;i++){
            data = new byte [1024];
        }
        List<GarbageCollectorMXBean> mxBeans =  ManagementFactory.getGarbageCollectorMXBeans();
        Iterator<GarbageCollectorMXBean> iterator = mxBeans.iterator();
        while(iterator.hasNext()){
            GarbageCollectorMXBean mxBean =    iterator.next();
            String name = mxBean.getName();
            long  collectionCount = mxBean.getCollectionCount();
            long   collectionTime = mxBean.getCollectionTime();
            LogFactory.getLog().info("gcName:"+name+",collectionCount:"+collectionCount+",collectionTime:"+collectionTime);
        }
    }
    public static void main(String args []){
        ManagementFactoryTester tester = new ManagementFactoryTester();
        tester.getGCMessage();
    }
}
